<!DOCTYPE html>
<html>
<head>
    

    

    



    <meta charset="utf-8">
    
    
    
    
    <title>cesium|挖地形，地形坡度和模拟地形淹没 | 一只咸鱼 | 努力学习最新姿势！！！</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="Cesium">
    <meta name="description" content="效果挖地形 通过绘制多边形获取边界点集合，把边界点分别计算生成多个ClippingPlane面 ，用ClippingPlaneCollection接口生成裁剪地形效果。最后分别将侧边和底部加上贴图效果 淹没分析 通过绘制多边形获取边界点集合，用extrudedHeight属性动态控制淹没高度，简单模拟淹没效果。熟悉webgl的可以通过修改shader的顶点和片段着色器创建淹没效果 坡度分析(地形)">
<meta property="og:type" content="article">
<meta property="og:title" content="cesium|挖地形，地形坡度和模拟地形淹没">
<meta property="og:url" content="http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/index.html">
<meta property="og:site_name" content="一只咸鱼">
<meta property="og:description" content="效果挖地形 通过绘制多边形获取边界点集合，把边界点分别计算生成多个ClippingPlane面 ，用ClippingPlaneCollection接口生成裁剪地形效果。最后分别将侧边和底部加上贴图效果 淹没分析 通过绘制多边形获取边界点集合，用extrudedHeight属性动态控制淹没高度，简单模拟淹没效果。熟悉webgl的可以通过修改shader的顶点和片段着色器创建淹没效果 坡度分析(地形)">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200420140748304.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MDkwMjUyNw==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200420132838821.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MDkwMjUyNw==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200420125245852.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MDkwMjUyNw==,size_16,color_FFFFFF,t_70">
<meta property="article:published_time" content="2020-04-20T06:27:00.000Z">
<meta property="article:modified_time" content="2020-04-20T08:26:22.134Z">
<meta property="article:author" content="Mr.Zhang">
<meta property="article:tag" content="Cesium">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/20200420140748304.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MDkwMjUyNw==,size_16,color_FFFFFF,t_70">
    
        <link rel="alternate" type="application/atom+xml" title="一只咸鱼" href="/atom.xml">
    
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

<meta name="generator" content="Hexo 4.2.0"></head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">Mr.Zhang</h5>
          <a href="mailto:zhangticcc@163.com" title="zhangticcc@163.com" class="mail">zhangticcc@163.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                首页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                时间轴
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                标签
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/categories"  >
                <i class="icon icon-lg icon-th-list"></i>
                分类
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://weibo.com/u/5392412243" target="_blank" >
                <i class="icon icon-lg icon-weibo"></i>
                微博
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/zhangti0708" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                开源地址
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://blog.csdn.net/weixin_40902527" target="_blank" >
                <i class="icon icon-lg icon-rss"></i>
                技术博客
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="http://zhangticcc.gitee.io/webgis/" target="_blank" >
                <i class="icon icon-lg icon-globe"></i>
                GIS案例
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://mp.weixin.qq.com/s/p4TOhKcr4RZkZWzuMYyBEQ" target="_blank" >
                <i class="icon icon-lg icon-weixin"></i>
                微信订阅号
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">cesium|挖地形，地形坡度和模拟地形淹没</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">cesium|挖地形，地形坡度和模拟地形淹没</h1>
        <h5 class="subtitle">
            
                <time datetime="2020-04-20T06:27:00.000Z" itemprop="datePublished" class="page-time">
  2020-04-20
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/GIS/">GIS</a></li></ul>

            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#效果"><span class="post-toc-number">1.</span> <span class="post-toc-text">效果</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#说明"><span class="post-toc-number">2.</span> <span class="post-toc-text">说明</span></a></li></ol>
        </nav>
    </aside>


<article id="post-sium-挖地形和模拟地形淹没"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">cesium|挖地形，地形坡度和模拟地形淹没</h1>
        <div class="post-meta">
            <time class="post-time" title="2020-04-20 14:27:00" datetime="2020-04-20T06:27:00.000Z"  itemprop="datePublished">2020-04-20</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/GIS/">GIS</a></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h3 id="效果"><a href="#效果" class="headerlink" title="效果"></a>效果</h3><p>挖地形<br><img alt="" height="430" src="https://img-blog.csdnimg.cn/20200420140748304.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MDkwMjUyNw==,size_16,color_FFFFFF,t_70" width="700"></p>
<p><code>通过绘制多边形获取边界点集合，把边界点分别计算生成多个ClippingPlane面 ，用ClippingPlaneCollection接口生成裁剪地形效果。最后分别将侧边和底部加上贴图效果</code></p>
<p>淹没分析<br><img alt="" height="430" src="https://img-blog.csdnimg.cn/20200420132838821.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MDkwMjUyNw==,size_16,color_FFFFFF,t_70" width="700"></p>
<p><code>通过绘制多边形获取边界点集合，用extrudedHeight属性动态控制淹没高度，简单模拟淹没效果。熟悉webgl的可以通过修改shader的顶点和片段着色器创建淹没效果</code></p>
<p>坡度分析(地形)<br><img alt="" height="430" src="https://img-blog.csdnimg.cn/20200420125245852.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MDkwMjUyNw==,size_16,color_FFFFFF,t_70" width="700"><br><code>通过绘制多段线获取线段点集合，用lerp获取点的线性插值结果，将返回的差值点高程绘制出来，实现坡度图</code></p>
<h3 id="说明"><a href="#说明" class="headerlink" title="说明"></a>说明</h3><p>挖地形插件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">import Cesium from &#39;..&#x2F;namespace&#39;</span><br><span class="line"></span><br><span class="line">function TerrainClipPlan(t, i) &#123;</span><br><span class="line">    this.viewer &#x3D; t,</span><br><span class="line">    this.options &#x3D; i || &#123;&#125;,</span><br><span class="line">    this._positions &#x3D; i.positions,</span><br><span class="line">    this._height &#x3D; this.options.height || 0,</span><br><span class="line">    this.bottomImg &#x3D; i.bottomImg,</span><br><span class="line">    this.wallImg &#x3D; i.wallImg,</span><br><span class="line">    this.splitNum &#x3D; Cesium.defaultValue(i.splitNum, 50),</span><br><span class="line">    this._positions &amp;&amp; this._positions.length &gt; 0 &amp;&amp; this.updateData(this._positions)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">Object.defineProperties(TerrainClipPlan.prototype, &#123;</span><br><span class="line">    show: &#123;</span><br><span class="line">        get: function () &#123;</span><br><span class="line">            return this._show</span><br><span class="line">        &#125;,</span><br><span class="line">        set: function (e) &#123;</span><br><span class="line">            this._show &#x3D; e, this.viewer.scene.globe.clippingPlanes &amp;&amp; (this.viewer.scene.globe.clippingPlanes.enabled &#x3D; e), this._switchExcavate(e)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line"></span><br><span class="line">    height: &#123;</span><br><span class="line">        get: function () &#123;</span><br><span class="line">            return this._height</span><br><span class="line">        &#125;,</span><br><span class="line">        set: function (e) &#123;</span><br><span class="line">            this._height &#x3D; e, this._updateExcavateDepth(e)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">TerrainClipPlan.prototype.updateData &#x3D; function (e) &#123;</span><br><span class="line">    this.clear();</span><br><span class="line">    var t &#x3D; [],</span><br><span class="line">        i &#x3D; e.length,</span><br><span class="line">        a &#x3D; new Cesium.Cartesian3,</span><br><span class="line">        n &#x3D; Cesium.Cartesian3.subtract(e[0], e[1], a);</span><br><span class="line">    n &#x3D; n.x &gt; 0, this.excavateMinHeight &#x3D; 9999;</span><br><span class="line">    for (var r &#x3D; 0; r &lt; i; ++r) &#123;</span><br><span class="line">        var s &#x3D; (r + 1) % i,</span><br><span class="line">            l &#x3D; Cesium.Cartesian3.midpoint(e[r], e[s], new Cesium.Cartesian3),</span><br><span class="line">            u &#x3D; Cesium.Cartographic.fromCartesian(e[r]),</span><br><span class="line">            c &#x3D; this.viewer.scene.globe.getHeight(u) || u.height;</span><br><span class="line">        c &lt; this.excavateMinHeight &amp;&amp; (this.excavateMinHeight &#x3D; c);</span><br><span class="line">        var d, h &#x3D; Cesium.Cartesian3.normalize(l, new Cesium.Cartesian3);</span><br><span class="line">        d &#x3D; n ? Cesium.Cartesian3.subtract(e[r], l, new Cesium.Cartesian3) : Cesium.Cartesian3.subtract(e[s], l, new Cesium.Cartesian3), d &#x3D; Cesium.Cartesian3.normalize(d, d);</span><br><span class="line">        var f &#x3D; Cesium.Cartesian3.cross(d, h, new Cesium.Cartesian3);</span><br><span class="line">        f &#x3D; Cesium.Cartesian3.normalize(f, f);</span><br><span class="line">        var p &#x3D; new Cesium.Plane(f, 0),</span><br><span class="line">            m &#x3D; Cesium.Plane.getPointDistance(p, l);</span><br><span class="line">        t.push(new Cesium.ClippingPlane(f, m))</span><br><span class="line">    &#125;</span><br><span class="line">    this.viewer.scene.globe.clippingPlanes &#x3D; new Cesium.ClippingPlaneCollection(&#123;</span><br><span class="line">        planes: t,</span><br><span class="line">        edgeWidth: 1,</span><br><span class="line">        edgeColor: Cesium.Color.WHITE,</span><br><span class="line">        enabled: !0</span><br><span class="line">    &#125;), this._prepareWell(e), this._createWell(this.wellData)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">TerrainClipPlan.prototype.clear &#x3D; function () &#123;</span><br><span class="line"></span><br><span class="line">    this.viewer.scene.globe.clippingPlanes &amp;&amp; (this.viewer.scene.globe.clippingPlanes.enabled &#x3D; !1, this.viewer.scene.globe.clippingPlanes.removeAll(), this.viewer.scene.globe.clippingPlanes.isDestroyed() || this.viewer.scene.globe.clippingPlanes.destroy()), this.viewer.scene.globe.clippingPlanes &#x3D; void 0, this.bottomSurface &amp;&amp; this.viewer.scene.primitives.remove(this.bottomSurface), this.wellWall &amp;&amp; this.viewer.scene.primitives.remove(this.wellWall), delete this.bottomSurface, delete this.wellWall, this.viewer.scene.render()</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">TerrainClipPlan.prototype._prepareWell &#x3D; function (e) &#123;</span><br><span class="line">    var t &#x3D; this.splitNum,</span><br><span class="line">        i &#x3D; e.length;</span><br><span class="line">    if (0 !&#x3D; i) &#123;</span><br><span class="line">        for (var a &#x3D; this.excavateMinHeight - this.height, n &#x3D; [], r &#x3D; [], s &#x3D; [], l &#x3D; 0; l &lt; i; l++) &#123;</span><br><span class="line">            var u &#x3D; l &#x3D;&#x3D; i - 1 ? 0 : l + 1,</span><br><span class="line">                c &#x3D; Cesium.Cartographic.fromCartesian(e[l]),</span><br><span class="line">                d &#x3D; Cesium.Cartographic.fromCartesian(e[u]),</span><br><span class="line">                h &#x3D; [c.longitude, c.latitude],</span><br><span class="line">                f &#x3D; [d.longitude, d.latitude];</span><br><span class="line"></span><br><span class="line">            0 &#x3D;&#x3D; l &amp;&amp; (</span><br><span class="line">                s.push(new Cesium.Cartographic(h[0], h[1])),</span><br><span class="line">                r.push(Cesium.Cartesian3.fromRadians(h[0], h[1], a)),</span><br><span class="line">                n.push(Cesium.Cartesian3.fromRadians(h[0], h[1], 0)));</span><br><span class="line"></span><br><span class="line">            for (var p &#x3D; 1; p &lt;&#x3D; t; p++) &#123;</span><br><span class="line">                var m &#x3D; Cesium.Math.lerp(h[0], f[0], p &#x2F; t),</span><br><span class="line">                    g &#x3D; Cesium.Math.lerp(h[1], f[1], p &#x2F; t);</span><br><span class="line">                l &#x3D;&#x3D; i - 1 &amp;&amp; p &#x3D;&#x3D; t || (</span><br><span class="line">                    s.push(new Cesium.Cartographic(m, g)),</span><br><span class="line">                    r.push(Cesium.Cartesian3.fromRadians(m, g, a)),</span><br><span class="line">                    n.push(Cesium.Cartesian3.fromRadians(m, g, 0)))</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        this.wellData &#x3D; &#123;</span><br><span class="line">            lerp_pos: s,</span><br><span class="line">            bottom_pos: r,</span><br><span class="line">            no_height_top: n</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">TerrainClipPlan.prototype._createWell &#x3D; function (e) &#123;</span><br><span class="line">    if (Boolean(this.viewer.terrainProvider._layers)) &#123;</span><br><span class="line">        var t &#x3D; this;</span><br><span class="line">        this._createBottomSurface(e.bottom_pos);</span><br><span class="line">        var i &#x3D; Cesium.sampleTerrainMostDetailed(this.viewer.terrainProvider, e.lerp_pos);</span><br><span class="line">        Cesium.when(i, function (i) &#123;</span><br><span class="line">            for (var a &#x3D; i.length, n &#x3D; [], r &#x3D; 0; r &lt; a; r++) &#123;</span><br><span class="line">                var s &#x3D; Cesium.Cartesian3.fromRadians(i[r].longitude, i[r].latitude, i[r].height);</span><br><span class="line">                n.push(s)</span><br><span class="line">            &#125;</span><br><span class="line">            t._createWellWall(e.bottom_pos, n)</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">        this._createBottomSurface(e.bottom_pos);</span><br><span class="line">        this._createWellWall(e.bottom_pos, e.no_height_top)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">TerrainClipPlan.prototype._getMinHeight &#x3D; function (e) &#123;</span><br><span class="line">    let minHeight &#x3D; 5000000;</span><br><span class="line">    let minPoint &#x3D; null;</span><br><span class="line">    for (let i &#x3D; 0; i &lt; e.length; i++) &#123;</span><br><span class="line">        let height &#x3D; e[i][&#39;z&#39;];</span><br><span class="line">        if (height &lt; minHeight) &#123;</span><br><span class="line">            minHeight &#x3D; height;</span><br><span class="line">            minPoint &#x3D; this._ellipsoidToLonLat(e[i]);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    return minPoint.altitude;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">TerrainClipPlan.prototype._ellipsoidToLonLat &#x3D; function (c) &#123;</span><br><span class="line">    let ellipsoid &#x3D; this.viewer.scene.globe.ellipsoid;</span><br><span class="line">    let cartesian3 &#x3D; new Cesium.Cartesian3(c.x, c.y, c.z);</span><br><span class="line">    let cartographic &#x3D; ellipsoid.cartesianToCartographic(cartesian3);</span><br><span class="line">    let lat &#x3D; Cesium.Math.toDegrees(cartographic.latitude);</span><br><span class="line">    let lng &#x3D; Cesium.Math.toDegrees(cartographic.longitude);</span><br><span class="line">    let alt &#x3D; cartographic.height;</span><br><span class="line">    return &#123;</span><br><span class="line">        longitude: lng,</span><br><span class="line">        latitude: lat,</span><br><span class="line">        altitude: alt</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">TerrainClipPlan.prototype._createBottomSurface &#x3D; function (e) &#123;</span><br><span class="line">    if (e.length) &#123;</span><br><span class="line">        let minHeight &#x3D; this._getMinHeight(e);</span><br><span class="line">        let positions &#x3D; [];</span><br><span class="line">        for (let i &#x3D; 0; i &lt; e.length; i++) &#123;</span><br><span class="line">            let p &#x3D; this._ellipsoidToLonLat(e[i]);</span><br><span class="line">            positions.push(p.longitude);</span><br><span class="line">            positions.push(p.latitude);</span><br><span class="line">            positions.push(minHeight);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        let polygon &#x3D; new Cesium.PolygonGeometry(&#123;</span><br><span class="line">            polygonHierarchy: new Cesium.PolygonHierarchy(</span><br><span class="line">                Cesium.Cartesian3.fromDegreesArrayHeights(positions)</span><br><span class="line">            ),</span><br><span class="line">            perPositionHeight: true</span><br><span class="line">        &#125;);</span><br><span class="line">        let geometry &#x3D; Cesium.PolygonGeometry.createGeometry(polygon);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        var i &#x3D; new Cesium.Material(&#123;</span><br><span class="line">            fabric: &#123;</span><br><span class="line">                type: &quot;Image&quot;,</span><br><span class="line">                uniforms: &#123;</span><br><span class="line">                    image: this.bottomImg</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;),</span><br><span class="line">            a &#x3D; new Cesium.MaterialAppearance(&#123;</span><br><span class="line">                translucent: !1,</span><br><span class="line">                flat: !0,</span><br><span class="line">                material: i</span><br><span class="line">            &#125;);</span><br><span class="line">        this.bottomSurface &#x3D; new Cesium.Primitive(&#123;</span><br><span class="line">            geometryInstances: new Cesium.GeometryInstance(&#123;</span><br><span class="line">                geometry: geometry</span><br><span class="line">            &#125;),</span><br><span class="line">            appearance: a,</span><br><span class="line">            asynchronous: !1</span><br><span class="line">        &#125;), this.viewer.scene.primitives.add(this.bottomSurface)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">TerrainClipPlan.prototype._createWellWall &#x3D; function (e, t) &#123;</span><br><span class="line">    let minHeight &#x3D; this._getMinHeight(e);</span><br><span class="line">    let maxHeights &#x3D; [];</span><br><span class="line">    let minHeights &#x3D; [];</span><br><span class="line">    for (let i &#x3D; 0; i &lt; t.length; i++) &#123;</span><br><span class="line">        maxHeights.push(this._ellipsoidToLonLat(t[i]).altitude);</span><br><span class="line">        minHeights.push(minHeight);</span><br><span class="line">    &#125;</span><br><span class="line">    let wall &#x3D; new Cesium.WallGeometry(&#123;</span><br><span class="line">        positions: t,</span><br><span class="line">        maximumHeights: maxHeights,</span><br><span class="line">        minimumHeights: minHeights,</span><br><span class="line">    &#125;);</span><br><span class="line">    let geometry &#x3D; Cesium.WallGeometry.createGeometry(wall);</span><br><span class="line">    var a &#x3D; new Cesium.Material(&#123;</span><br><span class="line">        fabric: &#123;</span><br><span class="line">            type: &quot;Image&quot;,</span><br><span class="line">            uniforms: &#123;</span><br><span class="line">                image: this.wallImg</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;),</span><br><span class="line">        n &#x3D; new Cesium.MaterialAppearance(&#123;</span><br><span class="line">            translucent: !1,</span><br><span class="line">            flat: !0,</span><br><span class="line">            material: a</span><br><span class="line">        &#125;);</span><br><span class="line">    this.wellWall &#x3D; new Cesium.Primitive(&#123;</span><br><span class="line">        geometryInstances: new Cesium.GeometryInstance(&#123;</span><br><span class="line">            geometry: geometry,</span><br><span class="line">            attributes: &#123;</span><br><span class="line">                color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.GREY)</span><br><span class="line">            &#125;,</span><br><span class="line">            id: &quot;PitWall&quot;</span><br><span class="line">        &#125;),</span><br><span class="line">        appearance: n,</span><br><span class="line">        asynchronous: !1</span><br><span class="line">    &#125;), this.viewer.scene.primitives.add(this.wellWall)</span><br><span class="line">&#125;</span><br><span class="line">TerrainClipPlan.prototype._switchExcavate &#x3D; function (e) &#123;</span><br><span class="line">    e ? (this.viewer.scene.globe.material &#x3D; Cesium.Material.fromType(&quot;WaJue&quot;), this.wellWall.show &#x3D; !0, this.bottomSurface.show &#x3D; !0) : (this.viewer.scene.globe.material &#x3D; null, this.wellWall.show &#x3D; !1, this.bottomSurface.show &#x3D; !1)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">TerrainClipPlan.prototype._updateExcavateDepth &#x3D; function (e) &#123;</span><br><span class="line">    this.bottomSurface &amp;&amp; this.viewer.scene.primitives.remove(this.bottomSurface), this.wellWall &amp;&amp; this.viewer.scene.primitives.remove(this.wellWall);</span><br><span class="line">    for (var t &#x3D; this.wellData.lerp_pos, i &#x3D; [], a &#x3D; t.length, n &#x3D; 0; n &lt; a; n++) i.push(Cesium.Cartesian3.fromRadians(t[n].longitude, t[n].latitude, this.excavateMinHeight - e));</span><br><span class="line">    this.wellData.bottom_pos &#x3D; i, this._createWell(this.wellData), this.viewer.scene.primitives.add(this.bottomSurface), this.viewer.scene.primitives.add(this.wellWall)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">export default TerrainClipPlan</span><br></pre></td></tr></table></figure>

<p>调用</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">let terrainClipPlan &#x3D; new TerrainClipPlan(this._viewer._delegate, &#123;</span><br><span class="line">      height: this._height,</span><br><span class="line">      splitNum: this._splitNum,</span><br><span class="line">      wallImg: this._wallImg,</span><br><span class="line">      bottomImg: this._bottomImg</span><br><span class="line">    &#125;)</span><br><span class="line">    </span><br><span class="line">    console.log(this._hierarchy.positions)</span><br><span class="line">    terrainClipPlan.updateData(this._hierarchy.positions)</span><br></pre></td></tr></table></figure>
        </div>

        <blockquote class="post-copyright">
    
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2020-04-20T08:26:22.134Z" itemprop="dateUpdated">2020-04-20 16:26:22</time>
</span><br>


        
        这里可以写作者留言，标签和 hexo 中所有变量及辅助函数等均可调用，示例：<a href="/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/" target="_blank" rel="external">http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/</a>
        
    </div>
    
    <footer>
        <a href="http://yoursite.com">
            <img src="/img/avatar.jpg" alt="Mr.Zhang">
            Mr.Zhang
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Cesium/" rel="tag">Cesium</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/&title=《cesium|挖地形，地形坡度和模拟地形淹没》 — 一只咸鱼&pic=http://yoursite.com/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/&title=《cesium|挖地形，地形坡度和模拟地形淹没》 — 一只咸鱼&source=分享各种福利和姿势..." data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《cesium|挖地形，地形坡度和模拟地形淹没》 — 一只咸鱼&url=http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/&via=http://yoursite.com" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2020/04/20/cesium-%E7%8E%AF%E8%A7%86%E5%88%86%E6%9E%90/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">cesium|视线分析(环视，通视)</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2020/04/16/cesium-%E9%87%8F%E6%B5%8B%E5%B7%A5%E5%85%B7/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">cesium|三角量测</h4>
      </a>
    </div>
  
</nav>



    




















</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        谢谢大爷~
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="/img/wechat.jpg" alt="打赏二维码">
        </div>
        
        <label class="reward-toggle">
            <input id="rewardToggle" type="checkbox" class="reward-toggle-check"
                data-wechat="/img/wechat.jpg" data-alipay="/img/alipay.jpg">
            <div class="reward-toggle-ctrol">
                <span class="reward-toggle-item wechat">微信</span>
                <span class="reward-toggle-label"></span>
                <span class="reward-toggle-item alipay">支付宝</span>
            </div>
        </label>
        
    </div>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循 <a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>Mr.Zhang &copy; 2015 - 2020</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/&title=《cesium|挖地形，地形坡度和模拟地形淹没》 — 一只咸鱼&pic=http://yoursite.com/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/&title=《cesium|挖地形，地形坡度和模拟地形淹没》 — 一只咸鱼&source=分享各种福利和姿势..." data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《cesium|挖地形，地形坡度和模拟地形淹没》 — 一只咸鱼&url=http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/&via=http://yoursite.com" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="//api.qrserver.com/v1/create-qr-code/?data=http://yoursite.com/2020/04/20/sium-%E6%8C%96%E5%9C%B0%E5%BD%A2%E5%92%8C%E6%A8%A1%E6%8B%9F%E5%9C%B0%E5%BD%A2%E6%B7%B9%E6%B2%A1/" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '死鬼去哪里了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!又好了!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
